﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using TarreOA.TarreOADAL;

public partial class DutyReport_admin_EditDutyReport : System.Web.UI.Page
{
    public string[] nights = null;
    public string[] daytimes = null;
    public string[] fugles = null;
    public string[] daysArray = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            for(int i = 0; i < year.Items.Count; i++)
            {
                if(DateTime.Now.Year == int.Parse(year.Items[i].Value))
                {
                    year.Items[i].Selected = true;
                }
            }
            for(int i = 0; i < month.Items.Count; i++)
            {
                if(DateTime.Now.Month == int.Parse(month.Items[i].Value))
                {
                    month.Items[i].Selected = true;
                }
            }
        }
        Hashtable htWeek = new Hashtable();
        htWeek.Add("Monday", "周一");
        htWeek.Add("Tuesday", "周二");
        htWeek.Add("Wednesday", "周三");
        htWeek.Add("Thursday", "周四");
        htWeek.Add("Friday", "周五");
        htWeek.Add("Saturday", "<font color='red'>周六</font>");
        htWeek.Add("Sunday", "<font color='red'>周日</font>");
        SqlConnection sqlConn = SQLManager.GetConn();
        sqlConn.Open();
        int curYear = int.Parse(this.year.SelectedItem.Value);
        int curMonth = int.Parse(this.month.SelectedItem.Value);
        int days = DateTime.DaysInMonth(curYear, curMonth);
        string sql = "select * from dutyreport where [month] = " + curMonth + " and [year] = " + curYear + " order by [day] asc";
        SqlCommand sqlCmd = new SqlCommand(sql, sqlConn);
        SqlDataReader sqlDr = sqlCmd.ExecuteReader();
        if(sqlDr.HasRows)
        {
            nights = new string[days];
            daytimes = new string[days];
            fugles = new string[days];
            daysArray = new string[days];
            int i = 0;
            while(sqlDr.Read())
            {
                daysArray[i] = htWeek[DateTime.Parse(curYear + "-" + curMonth + "-" + sqlDr["day"].ToString()).DayOfWeek.ToString()].ToString();
                nights[i] = sqlDr["night"].ToString();
                daytimes[i] = sqlDr["daytime"].ToString();
                fugles[i] = sqlDr["fugle"].ToString();
                i++;
            }
        }
        if(sqlDr != null)
        {
            sqlDr.Close();
            sqlDr.Dispose();
        }
        if(sqlConn != null && sqlConn.State == ConnectionState.Open)
        {
            sqlConn.Close();
            sqlConn.Dispose();
        }
    }
}
